﻿//----------------------------------------------------------------
// Desc: 
// Edit: ShowLong, http://blog.csdn.net/showlong
//
// Date Created: 2009-10-13
//
// Update Date : 
//
// Copyright (c) Fuel4D (http://www.fuel4d.com), All rights reserved.
//
//----------------------------------------------------------------
#pragma once


#include "FUI_Base.h"


struct fuWidgetBase;


//----------------------------------------------------------------
//
//----------------------------------------------------------------
class FAPI FUIWidgetManager : public FUI_AutoClassFactory< fuWidgetBase, BYTE >
{
    FUI_DECLARE_CLASS(FUIWidgetManager)

public:
    explicit FUIWidgetManager();
    ~FUIWidgetManager();
    virtual void DelObject(fuWidgetBase*& p);

    FINLINE fuFontGroup* GetFont(WORD index);
    FINLINE WORD GetFontCount();
    FINLINE fuMenuGroup* GetMenuData(BYTE index);
    FINLINE BYTE GetMenuCount();

    // 加载UI资源文件
    bool LoadUI(const ACHAR* filename);
    bool LoadUI(const ACHAR* filename, BYTE* mem, size_t sz);
    // 从内存中加载UI资源
    bool LoadUI(BYTE* mem, size_t sz);
    // 清理数据
    void Clear();
    // 保存UI资源文件
    void FUDSave();

    FV_UI_FONT_GROUP vFontGroup;        // 字体组信息
    FV_UI_MENU_GROUP vMenuGroup;        // 菜单组
    FV_UI_RES_FILE vResFiles;           // 资源树
    FV_UI_BUTTON_GROUP vBtnGroup;       // 预置按钮组
    FV_UI_SCROLL_GROUP vSBbarGroup;     // 预置滚动条组

    struct FAPI CONFIG
    {
        ACHAR pch_file[80];
        ACHAR class_prefix[32];

        CONFIG(){ clear(); }
        void clear();
    } cfg;
    struct FAPI FUI_PATH
    {
        FUI_StringA szExe;        // [c:/kk/xxx.fud]
        FUI_StringA szDocPath;    // [c:/kk/xxx/]
        FUI_StringA szFilePath;   // [c:/kk/xxx/ufile/]
        FUI_StringA szResPath;    // [c:/kk/xxx/ures/]
        FUI_StringA szDocName;    // [xxx.fud]

        void init(const ACHAR* path);
        void clear();
        bool is_init();
    } fud;
};


//----------------------------------------------------------------
// 注意使用了下面两个宏以后，它所对应的控件 CXXXControl 的默认值也需要相应的设置
//----------------------------------------------------------------

// 用于控件的
#define FUI_WidgetControl_Auto_Mask_Function(name)\
    bool Is##name()         { return has(name, nCtrlMask);           }\
    void Set##name(bool vl) { return mask_set(name, vl, nCtrlMask);  }

// 用于基类的
#define FUI_WidgetBase_Auto_Mask_Function(name)\
    bool Is##name()         { return has(name, nBaseMask);           }\
    void Set##name(bool vl) { return mask_set(name, vl, nBaseMask);  }


#pragma pack(push, 1)


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetBase)

    enum BASE_PROP_INFO
    {
        BPI_Name, BPI_Back, BPI_Align, BPI_Rect, BPI_Fringe,
        BPI_FntIndex, BPI_FntEffect,
        BPI_TipsTxt, BPI_DrawTxt, BPI_TxtAlign,
        BPI_DragFringe, BPI_DragCtrl, BPI_JumpUI, 
        BPI_CanFocus, BPI_CanMessage, BPI_Visible, BPI_Disable, BPI_JumpAndClose,
        //BPI_AlwaysHMax, BPI_AlwaysVMax,
        BPI_EdgeOffsetT,BPI_EdgeOffsetB,BPI_EdgeOffsetL,BPI_EdgeOffsetR,BPI_EdgeOffset,
        BPI_Max,
    };
    struct SubObject
    {
        BYTE type;
        fuWidgetBase* addr;
    };
    fuWidgetBase(BYTE type, BYTE ctrl_mk, funit w, funit h, const ACHAR* name);

    BYTE            nTypeID;                // 类型（EF_UI_WIDGET_TYPE）
    ACHAR           szName[FUEL_UI_RES_NAME];// 控件名称
    FIDHASH         dwNameHash;             // 名称的HASH
    fuPicture       uBackPicture;           // 背景图片
    BYTE            nWidgetAlignMode;       // 控件对齐模式（EF_UI_ALIGN_MODE）
    fuRect          uVirtualRect;           // 虚拟区域(有效区域)
    WORD            nFringeSize;            // 边框尺寸（象素）
    fuFontProp      uFont;                  // 字体参数
    DWORD           nTipsLanguageID;        // TIPS 多语言ID
    DWORD           nDrawTextLangID;        // 显示文本多语言ID
    BYTE            nDrawTextAlignMode;     // 显示文本对齐模式（EF_UI_ALIGN_MODE）
    BYTE            bCanDragSize[4];        // 四个方向上边缘拖动能力(即改变自身尺寸)[上下左右]
    BYTE            nDragMode;              // 整体拖曳模式（EF_UI_DRAG_MODE）
    FIDHASH         nJumpUI;                // 单击后跳转界面
    SHORT           nEdgeOffset[4];         // 触边偏移[上下左右]
    BYTE            baseReserve[8];         // 保留备用

    enum enumBaseParamOPMask
    {
        CanFocus        = 1<<0,             // 能否获得焦点
        CanMessage      = 1<<1,             // 能否向界面发送消息
        Visible         = 1<<2,             // 控件可见性
        JumpAndClose    = 1<<3,             // 跳转界面后关闭
        //AlwaysHMax      = 1<<4,             // 始终横向最大化
        //AlwaysVMax      = 1<<5,             // 始终纵向最大化
        Disable         = 1<<7,             // 禁用控件
        EdgeOffsetT     = 1<<8,             // 4个触边偏移[上下左右]
        EdgeOffsetB     = 1<<9,
        EdgeOffsetL     = 1<<10,
        EdgeOffsetR     = 1<<11,
        DefaultBaseMask = CanMessage|Visible|JumpAndClose,
    };
    FUI_WidgetBase_Auto_Mask_Function(CanFocus)
    FUI_WidgetBase_Auto_Mask_Function(CanMessage)
    FUI_WidgetBase_Auto_Mask_Function(Visible)
    FUI_WidgetBase_Auto_Mask_Function(JumpAndClose)
    //FUI_WidgetBase_Auto_Mask_Function(AlwaysHMax)
    //FUI_WidgetBase_Auto_Mask_Function(AlwaysVMax)
    FUI_WidgetBase_Auto_Mask_Function(Disable)
    FUI_WidgetBase_Auto_Mask_Function(EdgeOffsetT)
    FUI_WidgetBase_Auto_Mask_Function(EdgeOffsetB)
    FUI_WidgetBase_Auto_Mask_Function(EdgeOffsetL)
    FUI_WidgetBase_Auto_Mask_Function(EdgeOffsetR)

    void SetName(const ACHAR* name)
    {
        memset(szName, 0, sizeof(szName));
        FUI_StrcpyA(szName, name);
        dwNameHash = FUI_GetHashA(name);
    }
#ifdef WIN32
    RECT GetVirtualRect()
    {
        RECT r = {(long)uVirtualRect.uPos.nX, (long)uVirtualRect.uPos.nY, (long)uVirtualRect.uSize.nW, (long)uVirtualRect.uSize.nH};
        return r;
    }
    void SetVirtualRect(RECT& rc)
    {
        uVirtualRect.uPos.nX  = (funit)rc.left;
        uVirtualRect.uPos.nY  = (funit)rc.top;
        uVirtualRect.uSize.nW = (funit)rc.right;
        uVirtualRect.uSize.nH = (funit)rc.bottom;
    }
    RECT GetDragFringe()
    {
        RECT r = {bCanDragSize[0]?1:0, bCanDragSize[1]?1:0, bCanDragSize[2]?1:0, bCanDragSize[3]?1:0};
        return r;
    }
    void SetDragFringe(RECT& rc)
    {
        bCanDragSize[0] = rc.left   ? 1 : 0;
        bCanDragSize[1] = rc.top    ? 1 : 0;
        bCanDragSize[2] = rc.right  ? 1 : 0;
        bCanDragSize[3] = rc.bottom ? 1 : 0;
    }
    RECT GetEdgeOffset()
    {
        RECT r = {nEdgeOffset[0],nEdgeOffset[1],nEdgeOffset[2],nEdgeOffset[3]};
        return r;
    }
    void SetEdgeOffset(RECT& rc)
    {
        FUI_RECT* ur = (FUI_RECT*)&rc;
        nEdgeOffset[0] = (SHORT)ur->T;
        nEdgeOffset[1] = (SHORT)ur->B;
        nEdgeOffset[2] = (SHORT)ur->L;
        nEdgeOffset[3] = (SHORT)ur->R;
    }
#endif

private:
    DWORD            nBaseMask;             // 基类用的掩码(32种值)
protected:
    DWORD            nCtrlMask;             // 控件使用的掩码(32种值)

    void mask_set(WORD test_mask, bool add, DWORD& data_mask)
    {
        if (add) data_mask |= test_mask;
        else     data_mask &= ~test_mask;
    }
    bool has(WORD test_mask, DWORD& data_mask)
    {
        return (data_mask & test_mask) != 0;
    }
};
typedef FUI_Vector< fuWidgetBase* > FV_UI_PWIDGET;


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetFrame : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetFrame)

    enum FRAME_PROP_INFO
    {
        FPI_WorkMode, FPI_TitleOffset,
        FPI_BackEx1, FPI_BackEx2, FPI_BackEx3, FPI_BackEx4, FPI_BackEx5,
        FPI_AnimMode, FPI_AnimTime,
        FPI_CanMove, FPI_AlwaysShow, FPI_ExactPick, FPI_LoadToTop, /*FPI_LoadHide,*/
        FPI_OpenCenter, FPI_ShowMax, FPI_Dynamic,
        FPI_Max,
    };

    fuWidgetFrame();

    BYTE				nWorkMode;          // 工作模式（EF_UI_WORK_MODE）
    short				nCaptionOffsetX;    // 标题X偏移位置
    short				nCaptionOffsetY;    // 标题Y偏移位置
    fuPicture			uExtendBack[5];     // 扩展背景图片(暂时只支持5张)
    BYTE				nAnimateMode;       // 界面的动画模式（如果不设置将按默认设置来）
    DWORD				nAnimateTime;       // 界面的动画动作时长
    BYTE				reserve[16];		// 保留备用

    enum FRAME_OP_MARK
    {
        CanMove         = 1<<0,             // 是否可被移动
        AlwaysShow      = 1<<1,             // 是否永远显示
        ExactPick       = 1<<2,             // 是否精确鼠标拾取
        LoadToTop       = 1<<3,             // 框架加载时加载到顶部
        //LoadHide        = 1<<4,             // 加载后隐藏
        OpenCenter      = 1<<5,             // 显示时屏幕居中
        ShowMax         = 1<<6,             // 最大化状态
        Dynamic         = 1<<7,             // 允许动态创建多份
        DefaultCtrlMask = CanMove|/*LoadHide|*/OpenCenter,
    };
    FUI_WidgetControl_Auto_Mask_Function(CanMove)
    FUI_WidgetControl_Auto_Mask_Function(AlwaysShow)
    FUI_WidgetControl_Auto_Mask_Function(ExactPick)
    FUI_WidgetControl_Auto_Mask_Function(LoadToTop)
    //FUI_WidgetControl_Auto_Mask_Function(LoadHide)
    FUI_WidgetControl_Auto_Mask_Function(OpenCenter)
    FUI_WidgetControl_Auto_Mask_Function(ShowMax)
    FUI_WidgetControl_Auto_Mask_Function(Dynamic)

#ifdef WIN32
    FINLINE POINT GetTitleOffset(){ POINT rt = {(long)nCaptionOffsetX, (long)nCaptionOffsetY}; return rt; }
    FINLINE void SetTitleOffset(POINT& pt){ nCaptionOffsetX = (short)pt.x, nCaptionOffsetY = (short)pt.y; }
#endif
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetText : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetText)

	enum TEXT_PROP_INFO
	{
		TPI_AutoLine,
        TPI_TxtOffset,
		TPI_Max
	};
    fuWidgetText();

    SHORT               nTxtOffsetX;
    SHORT               nTxtOffsetY;
    BYTE				reserve[4];		// 保留备用

    enum TEXT_OP_MARK
    {
        AutoLinefeed	= 1<<0,				// 自动换行
        DefaultCtrlMask		= 0,
    };
    FUI_WidgetControl_Auto_Mask_Function(AutoLinefeed)

#ifdef WIN32
    FINLINE POINT GetTxtOffset(){ POINT rt = {(long)nTxtOffsetX, (long)nTxtOffsetY}; return rt; }
    FINLINE void SetTxtOffset(POINT& pt){ nTxtOffsetX = (short)pt.x, nTxtOffsetY = (short)pt.y; }
#endif
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetPicture : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetPicture)

	enum PICTURE_PROP_INFO
	{
		PPI_Alpha, PPI_BlendOne,
        PPI_HorizontalReversal, PPI_VerticalReversal,
		PPI_Max
	};
    fuWidgetPicture();

    float				fAlpha;				// 透明度
    BYTE				reserve[8];		    // 保留备用

    enum PICTURE_OP_MARK
    {
        BlendOne		    = 1<<0,			// 颜色覆盖
        HorizontalReversal  = 1<<1,         // 横向翻转
        VerticalReversal    = 1<<2,         // 纵向翻转
        DefaultCtrlMask		= 0,
    };
    FUI_WidgetControl_Auto_Mask_Function(BlendOne)
    FUI_WidgetControl_Auto_Mask_Function(HorizontalReversal)
    FUI_WidgetControl_Auto_Mask_Function(VerticalReversal)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetEdit : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetEdit)

	enum EDIT_PROP_INFO
	{
		EPI_TxtLength, EPI_PicOver,
		EPI_ReadOnly, EPI_Password, EPI_Number,
		EPI_Max
	};
    fuWidgetEdit();

    WORD				nTextMaxLength;		// 文本最大输入长度
    fuPicture			uPicMouseOver;      // 鼠标悬停时图
    BYTE				reserve[16];        // 保留备用

    enum EDIT_OP_MARK
    {
        ReadOnly		= 1<<0,             // 是否只读
        Password		= 1<<1,             // 是否是密码形式
        Number			= 1<<2,             // 是否是数字形式
        DefaultCtrlMask		= 0,
    };
    FUI_WidgetControl_Auto_Mask_Function(ReadOnly)
    FUI_WidgetControl_Auto_Mask_Function(Password)
    FUI_WidgetControl_Auto_Mask_Function(Number)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetButton : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetButton)

	enum BUTTON_PROP_INFO
	{
		BPI_BtnGroup,
		BPI_BtnNormal, BPI_BtnSuspend, BPI_BtnPress, BPI_BtnDisable,
		BPI_FntNormal, BPI_FntSuspend, BPI_FntPress, BPI_FntDisable,
		BPI_TxtOffset, BPI_CloseBtn, BPI_MaxBtn, BPI_DisableState,
		BPI_Max
	};

    fuWidgetButton(BYTE type = eUWT_Button);

    WORD            nButtonGroupIndex;      // 按钮组索引
    fuPicture       uPicture[eUBS_Max];     // 按钮的四态：普通，悬停，按下，灰掉
    fuFontProp      nStateFontID[eUBS_Max]; // 按钮的四态字体
    short           nTextOffsetX;           // 文字X编移
    short           nTextOffsetY;           // 文字Y编移
    BYTE            reserve[16];            // 保留备用

    enum BUTTON_OP_MARK
    {
        CloseButton     = 1<<0,             // 是否是关闭按钮
        MaxButton       = 1<<1,             // 是否是最大化按钮
        DisableState    = 1<<2,             // 禁用按钮状态
        Selected        = 1<<3,             // 默认是否选中（由派生控件使用）
        DefaultCtrlMask = 0,
    };
    FUI_WidgetControl_Auto_Mask_Function(CloseButton)
    FUI_WidgetControl_Auto_Mask_Function(MaxButton)
    FUI_WidgetControl_Auto_Mask_Function(DisableState)

#ifdef WIN32
	FINLINE POINT GetTxtOffset(){ POINT rt = {(long)nTextOffsetX, (long)nTextOffsetY}; return rt; }
	FINLINE void SetTxtOffset(POINT& pt){ nTextOffsetX = (short)pt.x, nTextOffsetY = (short)pt.y; }
#endif
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetCheck : public fuWidgetButton
{
    FUI_DECLARE_STRUCT(fuWidgetCheck)

	enum CHECK_PROP_INFO
	{
		CPI_BoxSize, CPI_PicSel, CPI_Selected,
		CPI_Max,
        CPI_Begin = fuWidgetButton::BPI_Max,
	};
    fuWidgetCheck(BYTE type = eUWT_Check);

    short           nCheckBoxSize;          // 选框宽度
    fuPicture       uPictureSelect;         // 被选中时的勾表现形式

    FUI_WidgetControl_Auto_Mask_Function(Selected)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetRadio : public fuWidgetCheck
{
    FUI_DECLARE_STRUCT(fuWidgetRadio)

	enum RADIO_PROP_INFO
	{
		RPI_Group,
		RPI_Max,
		RPI_Begin = fuWidgetCheck::CPI_Begin + fuWidgetCheck::CPI_Max,
	};
    fuWidgetRadio();

    DWORD           dwGroupID;              // 单选框分组ID(在单个框架内部的组号)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetScrollBar : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetScrollBar)

	enum SCROLL_PROP_INFO
	{
		SPI_Group, 
		SPI_HideBar, SPI_HideCtrl, SPI_SuspendMode,SPI_NoUpDown,SPI_FullScroll,
		SPI_Max,
	};

    fuWidgetScrollBar(BYTE type = eUWT_ScrollBar);

    WORD            nScrollBarGroupIndex;   // 预置滚动条
    fuWidgetButton  btnUp;
    fuWidgetButton  btnBar;
    fuWidgetButton  btnDown;
    BYTE            reserve[16];            // 保留备用

    enum SCROLLBAR_OP_MARK
    {
        AutoHideBar         = 1<<0,         // 自动隐藏滑块
        AutoHideCtrl	    = 1<<1,         // 自动隐藏上下按钮
        SuspendMode         = 1<<2,         // 悬浮模式
        NoUpDown            = 1<<3,         // 无上下按钮
        FullScroll          = 1<<4,         // 全控件滚动
        DefaultCtrlMask     = 0,
    };
    FUI_WidgetControl_Auto_Mask_Function(AutoHideBar)
    FUI_WidgetControl_Auto_Mask_Function(AutoHideCtrl)
    FUI_WidgetControl_Auto_Mask_Function(SuspendMode)
    FUI_WidgetControl_Auto_Mask_Function(NoUpDown)
    FUI_WidgetControl_Auto_Mask_Function(FullScroll)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetScrollBarEx : public fuWidgetScrollBar
{
    FUI_DECLARE_STRUCT(fuWidgetScrollBarEx)

    fuWidgetScrollBarEx();

    fuWidgetButton  btnTop;                 // 到顶按钮
    fuWidgetButton  btnBottom;              // 到底按钮
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetList : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetList)

	enum LIST_PROP_INFO
	{
		LPI_PicSel, LPI_PicMoveOn, LPI_PicCheck, LPI_PicCheckBK, LPI_PicCross,
		LPI_LineHeight, LPI_CheckWidth,
        LPI_HasCheck, LPI_FullBack,
		LPI_Max
	};
    fuWidgetList();

    fuPicture       uPictureSelect;         // 选中底图
    fuPicture       uPictureMoveOn;         // 悬停底图
    fuPicture       uPictureCheck;          // 复选选中
    fuPicture       uPictureCheckBK;        // 复选底图
    fuPicture       uPictureCross;          // 交叉行图片
    WORD            nLineHeight;            // 行高
    WORD            nCheckWidth;            // 复选框宽度
    fuWidgetScrollBar uScrollBar;           // 滚动条
    BYTE            reserve[16];            // 保留备用

    enum LIST_OP_MARK
    {
        HasCheck    = 1<<0,                 // 是否有复选框
        FullBack    = 1<<1,                 // 整体背景绘制
        DefaultCtrlMask = FullBack,
    };
    FUI_WidgetControl_Auto_Mask_Function(HasCheck)
    FUI_WidgetControl_Auto_Mask_Function(FullBack)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetCombo : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetCombo)

    fuWidgetCombo();

    fuWidgetEdit    uEdit;
    fuWidgetButton  uButton;
    fuWidgetList    uList;
    BYTE            reserve[16];            // 保留备用

    enum COMBO_OP_MARK
    {
        DefaultCtrlMask = 0,
    };
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetTree : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetTree)

    enum TREE_PROP_INFO
    {
        TPI_PicAdd, TPI_PicSub, TPI_PicSel, TPI_PicMoveOn,
        TPI_PicCheck, TPI_PicCheckBK, TPI_PicCross,
        TPI_LineHeight, TPI_AddWidth, TPI_CheckWidth, TPI_ItemOffset,
        TPI_HasCheck, TPI_CheckLeft, TPI_FullBack, TPI_HideNullChild,
        TPI_Max
    };
    fuWidgetTree();

    fuPicture       uAddPicture;            // 加号
    fuPicture       uSubPicture;            // 减号
    fuPicture       uSelectPicture;         // 选中
    fuPicture       uMoveOnPicture;         // 悬停
    fuPicture       uPictureCheck;          // 复选选中
    fuPicture       uPictureCheckBK;        // 复选底图
    fuPicture       uPictureCross;          // 交叉行图片
    WORD            nLineHeight;            // 行高
    WORD            nAddWidth;              // 加号宽度
    WORD            nCheckWidth;            // 选框宽度
    fuWidgetScrollBar uScrollBar;           // 滚动条
    BYTE            nItemOffset;            // 子父偏移
    BYTE            reserve[15];            // 保留备用

    enum TREE_OP_MARK
    {
        HasCheck        = 1<<0,             // 是否有复选框
        CheckAtLeft     = 1<<1,             // 复选框是否在左边
        FullBack        = 1<<2,             // 整体背景绘制
        HideNullChild   = 1<<3,             // 隐藏无子节点
        DefaultCtrlMask = CheckAtLeft|FullBack,
    };
    FUI_WidgetControl_Auto_Mask_Function(HasCheck)
    FUI_WidgetControl_Auto_Mask_Function(CheckAtLeft)
    FUI_WidgetControl_Auto_Mask_Function(FullBack)
    FUI_WidgetControl_Auto_Mask_Function(HideNullChild)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetProgress : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetProgress)

    enum PROGRESS_PROP_INFO
    {
        PPI_PicProgress,
        PPI_Max,
    };
    fuWidgetProgress();

    fuPicture       uPictureProgress;
    BYTE            reserve[16];            // 保留备用

    enum PROGRESS_OP_MARK
    {
        DefaultCtrlMask = 0,
    };
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetArrayGrid : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetArrayGrid)

    enum ARRAYGRID_PROP_INFO
    {
        AGPI_Size, AGPI_Offset, AGPI_Step, AGPI_Count, AGPI_Back, AGPI_Disable,
        AGPI_FullBack,
        AGPI_Max,
    };
    fuWidgetArrayGrid(BYTE type = eUWT_ArrayGrid);

    WORD            nArrayWidth;            // 格子宽度
    WORD            nArrayHeight;           // 格子高度
    WORD            nArrayOffsetX;          // 阵列X起点偏移
    WORD            nArrayOffsetY;          // 阵列Y起点偏移
    WORD            nArrayStepX;            // X方向阵列间距离
    WORD            nArrayStepY;            // Y方向阵列间距离
    WORD            nArrayCountX;           // X方向上数量
    WORD            nArrayCountY;           // Y方向上数量
    fuPicture       uGridBack;              // 阵列格子图片
    fuPicture       uGridDisable;           // 该格无效时图
    BYTE            reserve[16];            // 保留备用

    FINLINE POINT GetSize(){ POINT rt = {(long)nArrayWidth, (long)nArrayHeight}; return rt; }
    FINLINE void SetSize(POINT& pt){ nArrayWidth = (WORD)pt.x, nArrayHeight = (WORD)pt.y; }
    FINLINE POINT GetOffset(){ POINT rt = {(long)nArrayOffsetX, (long)nArrayOffsetY}; return rt; }
    FINLINE void SetOffset(POINT& pt){ nArrayOffsetX = (WORD)pt.x, nArrayOffsetY = (WORD)pt.y; }
    FINLINE POINT GetStep(){ POINT rt = {(long)nArrayStepX, (long)nArrayStepY}; return rt; }
    FINLINE void SetStep(POINT& pt){ nArrayStepX = (WORD)pt.x, nArrayStepY = (WORD)pt.y; }
    FINLINE POINT GetCount(){ POINT rt = {(long)nArrayCountX, (long)nArrayCountY}; return rt; }
    FINLINE void SetCount(POINT& pt){ nArrayCountX = (WORD)pt.x, nArrayCountY = (WORD)pt.y; }

    enum ARRAYGRID_OP_MARK
    {
        FullBack    = 1<<0,                 // 整体背景绘制
        DefaultCtrlMask = FullBack,
    };

    FUI_WidgetControl_Auto_Mask_Function(FullBack)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetArrayGridEx : public fuWidgetArrayGrid
{
    FUI_DECLARE_STRUCT(fuWidgetArrayGridEx)

    enum ARRAYGRIDEX_PROP_INFO
    {
        AEPI_Max,
        AEPI_Begin = fuWidgetArrayGrid::AGPI_Max,
    };
    fuWidgetArrayGridEx(BYTE type = eUWT_ArrayGridEx);

    fuWidgetScrollBar uScrollBar;           // 滚动条
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetContainer : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetContainer)

    fuWidgetContainer();
    ~fuWidgetContainer();
    void release();

    SubObject       subObjs[FUEL_UI_SUB_COUNT];// 子控件列表(保存时将addr清零)
    BYTE            reserve[16];            // 保留备用

    enum CONTAINER_OP_MARK
    {
        //UpWhenMiddle = 1<<0,                // 当左中或者右中模式下是上还是下
        DefaultCtrlMask/* = UpWhenMiddle*/,
    };
    //FUI_WidgetControl_Auto_Mask_Function(UpWhenMiddle)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetReport : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetReport)

    enum REPORT_PROP_INFO
    {
        RPI_HeadNormal, RPI_HeadSuspend, RPI_HeadDown,
        RPI_ItemNormal, RPI_LineSel, RPI_LineSuspend,
        RPI_HeadHeight, RPI_LineHeight, RPI_HeadTxtAlign, RPI_ItemTxtAlign,
        RPI_Sort, RPI_FullHead, RPI_FullItem, RPI_HideHead, RPI_LineCorss, RPI_FullBack,
        RPI_Max
    };
    fuWidgetReport();

    fuPicture       uHeadNormal;            // 头普通图片
    fuPicture       uHeadSuspend;           // 鼠标悬停在头上图片
    fuPicture       uHeadDown;              // 头按下图处
    fuPicture       uItemNormal;            // 单项图片
    fuPicture       uLineSelect;            // 单行选中
    fuPicture       uLineSuspend;           // 单行悬停
    fuPicture       uUprightLine;           // 分隔分（未开放）
    WORD            nHeadHeight;            // 头高
    WORD            nLineHeight;            // 行高
    BYTE            nHeadTextAlignMode;     // 头的文本排列模式
    BYTE            nItemTextAlignMode;     // 项的文本排列模式
    fuWidgetScrollBar uScrollBar;           // 滚动条
    BYTE            reserve[16];            // 保留备用

    enum REPORT_OP_MARK
    {
        ClickHeadSort       = 1<<0,         // 点击头自动排序
        HeadFullRowDraw     = 1<<1,         // 头图片整栏绘制
        ItemFullRowDraw     = 1<<2,         // 单项图片整栏绘制
        HideHead            = 1<<3,         // 是否隐藏报表头
        LineCorss           = 1<<4,         // 单行图交叉绘制
        FullBack            = 1<<5,         // 整体背景绘制
        DefaultCtrlMask = FullBack,
    };
    FUI_WidgetControl_Auto_Mask_Function(ClickHeadSort)
    FUI_WidgetControl_Auto_Mask_Function(HeadFullRowDraw)
    FUI_WidgetControl_Auto_Mask_Function(ItemFullRowDraw)
    FUI_WidgetControl_Auto_Mask_Function(HideHead)
    FUI_WidgetControl_Auto_Mask_Function(LineCorss)
    FUI_WidgetControl_Auto_Mask_Function(FullBack)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetRichEdit : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetRichEdit)

    enum RICHEDIT_PROP_INFO
    {
        REPI_Length, REPI_ReadOnly, REPI_FullBack,
        REPI_Max
    };
    fuWidgetRichEdit();

    fuWidgetScrollBar uScrollBar;           // 滚动条
    WORD            nMaxLength;             // 最大输入长度
    BYTE            reserve[24];            // 保留备用

    enum RICHEDIT_OP_MARK
    {
        ReadOnly    = 1<<0,                 // 是否只读
        FullBack    = 1<<1,                 // 整体背景绘制
        DefaultCtrlMask = FullBack,
    };
    FUI_WidgetControl_Auto_Mask_Function(ReadOnly)
    FUI_WidgetControl_Auto_Mask_Function(FullBack)
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetSlider : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetSlider)

    fuWidgetSlider(BYTE type = eUWT_Slider);

    fuWidgetButton  btnButton;              // 滑块
    BYTE            reserve[16];            // 保留备用

    enum SLIDER_OP_MARK
    {
        DefaultCtrlMask = 0,
    };
};


//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetSliderEx : public fuWidgetSlider
{
    FUI_DECLARE_STRUCT(fuWidgetSliderEx)

    fuWidgetSliderEx();

    fuWidgetButton  btnLB;                  // 左移
    fuWidgetButton  btnRB;                  // 右移
};

//----------------------------------------------------------------
//
//----------------------------------------------------------------
struct FAPI fuWidgetRollup : public fuWidgetBase
{
    FUI_DECLARE_STRUCT(fuWidgetRollup)

    enum ROLLUP_PROP_INFO
    {
        RUPT_BarOpenN, RUPT_BarOpenS, RUPT_BarCloseN, RUPT_BarCloseS,
        RUPT_ItemBack, RUPT_ItemCross, RUPT_ItemSuspend, RUPT_ItemSelect,
        RUPT_BarHeight, RUPT_BarDistance, RUPT_ItemHeight, RUPT_ItemIndent,
        RUPT_FixedRect, RUPT_FullBack, RUPT_CoverCross, RUPT_SingleBar,
        RUPI_Max
    };

    fuWidgetRollup(BYTE type = eUWT_Rollup);

    fuPicture       uBarOpenN;              // 分类打开状态（普通）
    fuPicture       uBarOpenS;              // 分类打开状态（悬停）
    fuPicture       uBarCloseN;             // 分类关闭状态（普通）
    fuPicture       uBarCloseS;             // 分类关闭状态（悬停）
    fuPicture       uItemBack;              // 单项底图
    fuPicture       uItemCross;             // 单项交叉底图
    fuPicture       uItemSuspend;           // 单项悬停
    fuPicture       uItemSelect;            // 单项选中
    WORD            nBarHeight;             // 分类高度
    WORD            nBarDistance;           // 分类间距
    WORD            nItemHeight;            // 单项高度
    WORD            nItemIndent;            // 项树缩进
    fuWidgetScrollBar uScrollBar;           // 滑块参数
    BYTE            reserve[16];            // 保留备用

    enum ROLLUP_OP_MARK
    {
        FixedRect       = 1<<0,             // 锁定在控件区域内
        FullBack        = 1<<1,             // 整栏背景绘制
        CoverCross      = 1<<2,             // 覆盖交叉模式
        SingleBar       = 1<<3,             // 单一分类显示
        DefaultCtrlMask = FullBack,
    };
    FUI_WidgetControl_Auto_Mask_Function(FixedRect)
    FUI_WidgetControl_Auto_Mask_Function(FullBack)
    FUI_WidgetControl_Auto_Mask_Function(CoverCross)
    FUI_WidgetControl_Auto_Mask_Function(SingleBar)
};

//----------------------------------------------------------------
//
//----------------------------------------------------------------
class FAPI FUIWidgetDataFile
{
    FUI_DECLARE_STRUCT(FUIWidgetDataFile)

public:
    explicit FUIWidgetDataFile(FUIWidgetManager* wm = 0);
    ~FUIWidgetDataFile();

    void clear();
    int size();
    void init(int n);
    void set_type(int index, BYTE type);
    BYTE get_type(int index);
    fuWidgetBase* get_widget(int index);
    fuWidgetFrame* get_frame();
    WORD save(const ACHAR* filepath);
    void save(FUI_MemFile& kf);
    WORD load(const ACHAR* filepath);
    WORD load(BYTE* mem, size_t size);
    void CloneTo(FUIWidgetDataFile* out);
    WORD MakeCode(const ACHAR* name, FUI_StringA* cpp_file = 0, FUI_StringA* h_file = 0);

    FUIWidgetManager* pWM;
    struct FAPI Copyright
    {
    public:
        DWORD head;
        WORD ver;
        BYTE unitType;
        Copyright();
        FINLINE bool operator == (const Copyright& _right)
        {
            return head == _right.head && ver == _right.ver;
        }
    };

protected:
    Copyright uCopyright;
    fuWidgetFrame uFrameData;
    FV_UI_BYTE pWidgetTypes;
    FV_UI_PWIDGET ppWidgets;

    WORD load_container(FUI_MemFile& kf, fuWidgetContainer* wc);
    void save_container(FUI_MemFile& kf, fuWidgetContainer* wc);
    void clone_container(fuWidgetContainer* src, fuWidgetContainer* dst);
};


#pragma pack(pop)


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#include "FUI_Widget_inl.h"
